package com.igda.activities.tihbms.views;

import android.content.Context;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.igda.tihbms.controllers.LogicController;

public class GameView extends SurfaceView implements SurfaceHolder.Callback {

	private LogicController logic;

	private Context context;

	public GameView(Context context) {
		super(context, null);
		this.context = context;
	}

	public void init() {
		SurfaceHolder holder = getHolder();
		holder.addCallback(this);

		this.logic = new LogicController(holder, this.context);
		this.logic.init(context.getResources());

		this.setFocusable(true);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		this.logic.input(event);

		return true;
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		this.logic.screenVisible(this.getHolder());
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		this.logic.screenDestroyed();
	}

}